package cn.wsalix.templet.entity;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import lombok.Data;
import lombok.EqualsAndHashCode;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import cn.anlaser.entity.SimpleEntity;
import cn.wsalix.templet.type.PlaceDataEnum;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * @author jskyme 模板位置
 */
@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "SITE_PAGE_PLACE")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@EntityListeners({ AuditingEntityListener.class })
@Data
@EqualsAndHashCode(callSuper = false)
public class SitePagePlace extends SimpleEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8690858787848487490L;
	private String placeCode;
	private PlaceDataEnum dataType;
	/**
	 * 1,单篇文章ID 2,多篇文章分类ID 3,单个菜单ID 4,多个菜单父ID 5，单个分类ID 6，分类父id 5,单个广告ID
	 */
	private Long fkId;// 数据外键
	@JsonIgnore
	@ManyToOne(cascade = CascadeType.MERGE, optional = true, fetch = FetchType.LAZY)
	@JoinColumn(foreignKey = @ForeignKey(name = "FK_PAGE_PLACE_SITE"), name = "SITE_ID")
	private SiteInfo siteInfo;
	
	@ManyToOne(cascade = CascadeType.MERGE, optional = false, fetch = FetchType.LAZY)
	@JoinColumn(foreignKey = @ForeignKey(name = "FK_PAGE_PLACE_SITEPAGE"), name = "SITE_PAGE_ID")	
	private SitePage sitePage;

	@ManyToOne(cascade = CascadeType.MERGE, optional = false, fetch = FetchType.LAZY)
	@JoinColumn(foreignKey = @ForeignKey(name = "FK_PAGE_PLACE_TPP"), name = "TEMPLET_PAGE_PLACE_ID")
	private TempletPagePlace TempletPagePlace;

}
